package zz.note.rabbitmq.direct;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @Author: ZZ
 * @date 2022/2/11
 */
@Component
public class DirectOrderService {
	@Autowired
	private RabbitTemplate rabbitTemplate;
	// 1: 定义交换机
	private String exchangeName = "direct_order_exchange";
	// 2: 路由key
	private String routeKey = "phone.email";
	public void makeOrder(String userId, int num) {
		// 模拟用户下单
		String orderNumer = UUID.randomUUID().toString();
		// 发送订单信息给RabbitMQ fanout
		rabbitTemplate.convertAndSend(exchangeName, routeKey, orderNumer);
	}
}
